import { Button, Checkbox, Form, Input, Col, message } from "antd";
import "./index.scss";
import PageName from "../../../../../components/PageName/index.jsx";
import { AddAuthorityUser } from "../../../../../utils/httpAllMethods/AuthHttp.jsx";
import { useNavigate } from "react-router-dom";
const onFinishFailed = (errorInfo) => {
};
const AddAuthority = () => {
  const navigator = useNavigate();
  const [form] = Form.useForm();
  const onSearchMsg = (value) => {
    let authAll = [
      value.floor,
      value.require,
      value.content,
      value.consult,
      value.activity,
      value.web,
      value.user,
      value.params,
      value.auth,
    ];
    let admin_authority = authAll.flat().filter((value) => value !== undefined);
    AddAuthorityUser({
      // 账号
      admin_name: value.admin, // 姓名
      admin_nickname: value.name, // 手机号
      admin_tel: value.phoneNumber, // 授权城市
      admin_city: value.city.join(), // 权限
      admin_authority: admin_authority.join(),
    }).then(() => {
      message.success('添加成功!')
      navigator('/home/Authority')
    });
  };
  const quit = () => {
    navigator("/home/Authority");
  };
  return (
    <>
      <PageName name="添加用户"></PageName>
      <Form
        style={{ marginTop: "20px" }}
        colon={false}
        onFinish={onSearchMsg}
        form={form}
        name="basic"
        labelCol={{
          span: 2,
        }}
        wrapperCol={{
          span: 6,
        }}
        initialValues={{
          remember: true,
        }}
        onFinishFailed={onFinishFailed}
        autoComplete="off"
      >
        <Form.Item
          label="账号"
          name="admin"
          labelAlign="right"
          wrapperCol={{
            span: 8,
          }}
          rules={[
            {
              required: true,
              message: "Please input your username!",
            },
          ]}
        >
          <div
            className="item"
            style={{ display: "flex", alignItems: "baseline" }}
          >
            <Col span={18}>
              <Input></Input>
            </Col>
            <span style={{ marginLeft: "10px", color: "#cccccc" }}>
              默认密码：123
            </span>
          </div>
        </Form.Item>

        <Form.Item
          label="姓名"
          name="name"
          wrapperCol={{
            span: 6,
          }}
          rules={[
            {
              required: true,
              message: "Please input your password!",
            },
          ]}
        >
          <Input />
        </Form.Item>

        <Form.Item
          label="手机号"
          name="phoneNumber"
          wrapperCol={{
            span: 6,
          }}
          rules={[
            {
              required: true,
              message: "Please input your password!",
            },
          ]}
        >
          <Input />
        </Form.Item>

        <p className="cityAuth">授权城市</p>

        <Form.Item
          label=" "
          name="city"
          labelCol={{
            span: 1,
          }}
          wrapperCol={{
            span: 6,
          }}
        >
          <Checkbox.Group>
            <Checkbox
              value="北京"
              style={{
                lineHeight: "32px",
              }}
            >
              北京
            </Checkbox>
            <Checkbox
              value="上海"
              style={{
                lineHeight: "32px",
              }}
            >
              上海
            </Checkbox>
            <Checkbox
              value="广州"
              style={{
                lineHeight: "32px",
              }}
            >
              广州
            </Checkbox>
            <Checkbox
              value="深圳"
              style={{
                lineHeight: "32px",
              }}
            >
              深圳
            </Checkbox>
          </Checkbox.Group>
        </Form.Item>
        <p className="cityAuth">权限分配</p>
        <Form.Item label="楼盘管理" name="floor">
          <Checkbox.Group>
            <Checkbox
              value="1"
              style={{
                lineHeight: "32px",
              }}
            >
              新房
            </Checkbox>
          </Checkbox.Group>
        </Form.Item>
        <Form.Item label="需求管理" name="require">
          <Checkbox.Group>
            <Checkbox
              value="2"
              style={{
                lineHeight: "32px",
              }}
            >
              需求管理
            </Checkbox>
          </Checkbox.Group>
        </Form.Item>
        <Form.Item label="内容审核" name="content">
          <Checkbox.Group>
            <Checkbox
              value="3"
              style={{
                lineHeight: "32px",
                width: "130px",
              }}
            >
              楼盘点评
            </Checkbox>
            <Checkbox
              value="4"
              style={{
                lineHeight: "32px",
                width: "130px",
              }}
            >
              楼盘解读
            </Checkbox>
            <Checkbox
              value="5"
              style={{
                lineHeight: "32px",
                width: "130px",
              }}
            >
              经纪人点评
            </Checkbox>
            <Checkbox
              value="6"
              style={{
                lineHeight: "32px",
                width: "130px",
              }}
            >
              服务案例
            </Checkbox>
          </Checkbox.Group>
        </Form.Item>
        <Form.Item label="咨询管理" name="consult">
          <Checkbox.Group>
            <Checkbox
              value="7"
              style={{
                lineHeight: "32px",
              }}
            >
              行业资讯
            </Checkbox>
          </Checkbox.Group>
        </Form.Item>
        <Form.Item label="活动管理" name="activity">
          <Checkbox.Group>
            <Checkbox
              value="8"
              style={{
                lineHeight: "32px",
              }}
            >
              红包活动
            </Checkbox>
          </Checkbox.Group>
        </Form.Item>
        <Form.Item label="网站管理" name="web">
          <Checkbox.Group>
            <Checkbox
              value="9"
              style={{
                lineHeight: "32px",
              }}
            >
              焦点图
            </Checkbox>
            <Checkbox
              value="10"
              style={{
                lineHeight: "32px",
              }}
            >
              广告
            </Checkbox>
          </Checkbox.Group>
        </Form.Item>
        <Form.Item label="用户管理" name="user">
          <Checkbox.Group>
            <Checkbox
              value="11"
              style={{
                lineHeight: "32px",
              }}
            >
              个人用户
            </Checkbox>
            <Checkbox
              value="12"
              style={{
                lineHeight: "32px",
              }}
            >
              经纪人
            </Checkbox>
          </Checkbox.Group>
        </Form.Item>
        <Form.Item label="参数配置" name="params">
          <Checkbox.Group>
            <Checkbox
              value="13"
              style={{
                lineHeight: "32px",
              }}
            >
              城市区域
            </Checkbox>
            <Checkbox
              value="14"
              style={{
                lineHeight: "32px",
              }}
            >
              轨道交通
            </Checkbox>
            <Checkbox
              value="15"
              style={{
                lineHeight: "32px",
              }}
            >
              项目特色
            </Checkbox>
          </Checkbox.Group>
        </Form.Item>
        <Form.Item label="权限管理" name="auth">
          <Checkbox.Group>
            <Checkbox
              value="16"
              style={{
                lineHeight: "32px",
              }}
            >
              权限
            </Checkbox>
          </Checkbox.Group>
        </Form.Item>

        <div className="btn-all">
          <Button type="primary" htmlType="submit" className="btn">
            确认
          </Button>
          <Button className="btn" onClick={quit}>
            取消
          </Button>
        </div>
      </Form>
    </>
  );
};
export default AddAuthority;
